/**
 * <p>设备操作的工厂类
 * @Title: DeviceOperationFactory.java
 * @Package com.rushswise.lovetrip.commonfactory
 * @Description: 详细说明该类的作用
 * Copyright: Copyright (c) 2013-2013 All rights reserved
 * Company: 
 * 
 * @author Rush Song-Administrator
 * @date 2013-8-10 下午9:01:47
 * @version V1.0
 */
package com.rushswise.lovetrip.commonfactory;

import java.util.ArrayList;
import java.util.List;

import com.rushswise.lovetrip.commoninterface.DeviceFunOperation;
import com.rushswise.lovetrip.commoninterface.DeviceType;
import com.rushswise.lovetrip.gps.GpsDevicceOperation;

/**
 * <p> 简要描述类型的作用
 * @ClassName: DeviceOperationFactory
 * @Description: TODO
 * @author Rush Song-Administrator
 * @date 2013-8-10 下午9:01:47
 *
 */
public final class DeviceOperationFactory
{
    /**
     * 保存实例化后的类
     * */
    private List<DeviceFunOperation> deviceFunOperations = new ArrayList<DeviceFunOperation>();
    
    private DeviceOperationFactory()
    {
        //这里初始化所有的实现类，目前只有一个
        deviceFunOperations.add(new GpsDevicceOperation());
        
        
    }
    
    private static class SingletonHolder
    {
        public static final DeviceOperationFactory INSTANCE = new DeviceOperationFactory();
    }
    
    /**
      * 获取单例类
      *
      * @Title: getInstance
      * @Description: TODO
      * @param @return
      * @return DeviceOperationFactory
      * @throws
      */
    public static DeviceOperationFactory getInstance()
    {
        return SingletonHolder.INSTANCE;
    }
    
    /**
      * 根据传递的参数获取对应的操作句柄
      *
      * @Title: getDeviceInstnce
      * @Description: TODO
      * @param @param deviceType
      * @param @return
      * @return DeviceFunOperation
      * @throws
      */
    public DeviceFunOperation getDeviceInstnce(DeviceType deviceType)
    {
        if(null == deviceType)
        {
            return null;
        }
        DeviceFunOperation dstFunOperation = null;
        String operationType = deviceType.toString();
        
        FINDDEVICE:
        for(DeviceFunOperation currDeviceFunOperation : deviceFunOperations)
        {
            if(currDeviceFunOperation.getOperationType().equals(operationType))
            {
                dstFunOperation = currDeviceFunOperation;
                break FINDDEVICE;
            }
        }
        
        return dstFunOperation;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
